<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import equipmentProductManage from '@/api/equipment/equipmentProductManage'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  equipmentProductManage.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  equipmentProductManage.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_equipment_product_manage',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: equipmentProductManage.getList,
  recycleApi: equipmentProductManage.getRecycleList,
  add: {
    show: true,
    api: equipmentProductManage.save,
    auth: ['equipment:productManage:save']
  },
  edit: {
    show: true,
    api: equipmentProductManage.update,
    auth: ['equipment:productManage:update']
  },
  delete: {
    show: true,
    api: equipmentProductManage.deletes,
    auth: ['equipment:productManage:delete'],
    realApi: equipmentProductManage.realDeletes,
    realAuth: ['equipment:productManage:realDeletes']
  },
  recovery: {
    show: true,
    api: equipmentProductManage.recoverys,
    auth: ['equipment:productManage:recovery']
  },
  import: {
    show: true,
    url: 'equipment/productManage/import',
    templateUrl: 'equipment/productManage/downloadTemplate',
    auth: ['equipment:productManage:import']
  },
  export: {
    show: true,
    url: 'equipment/productManage/export',
    auth: ['equipment:productManage:export']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "产品标识",
    dataIndex: "type_name",
    formType: "input",
    search: true
  },
  {
    title: "产品名称",
    dataIndex: "name",
    formType: "input",
    search: true
  },
  {
    title: "产品图片",
    dataIndex: "name_image",
    formType: "upload",
    type: "image",
    multiple: false
  },
  {
    title: "产品分类",
    dataIndex: "product_id",
    formType: "select",
    search: true,
    dict: {
      url:"/equipment/productType/index",
      method:"get",
      params:{
        page:1,
        pageSize:1000
      },
      props:{
        label:"type_name",
        value:"id"
      },
      translation: true
    }
  },
  {
    title: "消息协议",
    dataIndex: "news_xy",
    formType: "select",
    search: true,
    dict: {
      name: "news_xy",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    }
  },
  {
    title: "接入方式",
    dataIndex: "cut_fs",
    formType: "select",
    search: true,
    dict: {
      name: "cut_fs",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    }
  },
  {
    title: "设备类型",
    dataIndex: "sb_type",
    formType: "select",
    search: true,
    dict: {
      name: "sb_type",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    }
  },
  {
    title: "产品描述",
    dataIndex: "describe",
    formType: "input",
    search: true
  },
  {
    title: "运行状态",
    dataIndex: "operation_status",
    formType: "select",
    search: true,
    dict: {
      name: "operation_status",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    }
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  }
])
</script>
<script> export default { name: 'equipment:productManage' } </script>